package com.psfd.demo.controller;

import com.psfd.demo.bean.Offer;
import com.psfd.demo.bean.Product;
import com.psfd.demo.service.OfferService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@RestController
public class OfferController {

    @Resource
    private OfferService offerService;

    @RequestMapping("/offerinsert")
    public ModelAndView insert(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("offeradd");
        return modelAndView;
    }


    @RequestMapping("/insertOffer")
    public ModelAndView add(Offer offer){
        System.err.println(offer+"1111111111111");
        offerService.save(offer);
        return queryAll();
    }




    @RequestMapping("/offerupdate")
    public ModelAndView offerupdate(Integer offerid){
        System.out.println(offerid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("offerid",offerid);
        modelAndView.setViewName("offerupdate");
        return modelAndView;
    }

    @RequestMapping("/updateOffer")
    public ModelAndView updateOffer(Offer offer){
        System.err.println(offer+"--------------------");
        offerService.updateById(offer);
        return queryAll();
    }

    @RequestMapping("/deleteOffer")
    public ModelAndView delete(Integer offerid){
        System.err.println(offerid+"....................");
        offerService.removeById(offerid);
        return queryAll();
    }


    @RequestMapping("/offerQueryAll")
    public ModelAndView queryAll(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("offerlist",offerService.list());
        modelAndView.setViewName("offerList");
        return modelAndView;
    }


//    @RequestMapping("/offerreturnpage")
//    public ModelAndView returnpage(){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setViewName("homepage");
//        return modelAndView;
//    }
}
